const mongoose = require("mongoose")
const router = require('koa-router')();
const User = require("../models/user")

mongoose.connect("mongodb://127.0.0.1:27017/koalogin")
mongoose.connection.on("connected", function () {
  console.log("success");

})
mongoose.connection.on("error", function () {
  console.log("fail");

})
mongoose.connection.on("disconnected", function () {
  console.log("disconnected");

})

router.get("/user",function (res) {
  User.find({},function(err,doc){
    if (err) {
      res.json({
        status:"1",
        msg:err.message
      })
    } else {
      res.json({
        status: "2",
        msg: "",
        result:doc
      })
    }
  })
})

module.exports=router